package com.aiju.cash.ui.signbank.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.ui.signbank.bean.CalculateAccountInfo;
import com.aiju.forexpand.addresspicker.SinglePicker;
import com.aiju.widgit.layout.SettingGroupView;
import com.aiju.widgit.layout.SettingItemEditView;
import com.aiju.widgit.layout.SettingItemRadioButton;
import com.aiju.widgit.layout.SettingItemTextView;

/**
 * @author: 流冥
 * @date: 2017-07-13
 * @Description: 结算账户信息提交
 */
public class CalculateAccountInfoActivity extends BaseTitleActivity {
    private SettingItemTextView bank_name;
    private SettingItemEditView person_name;
    private SettingItemEditView bank_account;
    private SettingItemRadioButton type;
    private SettingItemRadioButton account_person;
    private SettingItemTextView kinsfolk_type;
    private SettingItemEditView kinsfolk_code;
    private SettingGroupView layout;
    CalculateAccountInfo calculateAccountInfo = new CalculateAccountInfo();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculate_account_info);
        initView();
    }

    void initView() {
        mAiJuTitleBarView.setCenterTitle("结算账户信息提交");
        mAiJuTitleBarView.setRightTitle("提交");

        bank_name = (SettingItemTextView) findViewById(R.id.bank_name);
        person_name = (SettingItemEditView) findViewById(R.id.person_name);
        bank_account = (SettingItemEditView) findViewById(R.id.bank_account);
        type = (SettingItemRadioButton) findViewById(R.id.type);
        account_person = (SettingItemRadioButton) findViewById(R.id.account_person);
        kinsfolk_type = (SettingItemTextView) findViewById(R.id.kinsfolk_type);
        kinsfolk_code = (SettingItemEditView) findViewById(R.id.kinsfolk_code);
        layout = (SettingGroupView)findViewById(R.id.layout);
        person_name.setEditable(true);
        bank_account.setEditable(true);
        kinsfolk_code.setEditable(true);
        person_name.getRightView().setHint("请填写");
        bank_account.getRightView().setHint("请填写");
        kinsfolk_code.getRightView().setHint("请填写");
        type.setRadio1Text("对公账号");
        type.setRadio2Text("对私账号");
        account_person.setRadio1Text("法人本人");
        account_person.setRadio2Text("法人亲属");

        bank_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                calculateAccountInfo.toString();
            }
        });
        person_name.getRightView().addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                calculateAccountInfo.setPerson_name(s.toString().trim());
            }
        });
        bank_account.getRightView().addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                calculateAccountInfo.setBank_account(s.toString().trim());
            }
        });

        type.setChangeListener(new SettingItemRadioButton.OnChangeListener() {
            @Override
            public void change(String item) {
                calculateAccountInfo.setType(item);
            }
        });
        account_person.setChangeListener(new SettingItemRadioButton.OnChangeListener() {
            @Override
            public void change(String item) {
                calculateAccountInfo.setAccount_person(item);
            }
        });
        kinsfolk_type.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showtype("法人亲属证件类型");
            }
        });
        kinsfolk_code.getRightView().addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                calculateAccountInfo.setKinsfolk_code(s.toString().trim());
            }
        });
        showViewByTag(2);

    }

    void showtype(String title) {
        SinglePicker dataPicker = new SinglePicker();
        dataPicker.selectAddressDialog(this, kinsfolk_type.getRightView(), R.array.type);
        dataPicker.getTitleTextView().setText(title);
        dataPicker.setChangeCity(new SinglePicker.OnChangeCity() {
            @Override
            public void onChangeCity(String province) {
                calculateAccountInfo.setKinsfolk_type(province);
            }
        });
    }


    void showViewByTag(int tag) {
        switch (tag) {
            case 0:// 结算账户人身份，法人亲属证件类型，法人亲属证件号码隐藏
                layout.setVisibility(View.INVISIBLE);
                break;
            case 1:// 结算账户人身份显示
                kinsfolk_type.setVisibility(View.GONE);
                kinsfolk_code.setVisibility(View.GONE);
                break;
            case 2:// 全都不隐藏
                break;
        }

    }

}
